use alloc::string::{String, ToString};
use kdriver::KDriverScheme;
use memory::MemoryScheme;
use proc::ProcScheme;
use root::RootScheme;
use spin::{Lazy, Mutex};
use syscall::scheme::SchemeRef;
use user::UserScheme;

pub mod kdriver;
pub mod memory;
pub mod op;
pub mod proc;
pub mod root;
pub mod user;

pub static ROOT_SCHEME: Lazy<Mutex<SchemeRef>> = Lazy::new(|| Mutex::new(RootScheme::new()));

pub fn init() {
    ROOT_SCHEME
        .lock()
        .write()
        .when_mounted("/".to_string(), None);

    MemoryScheme::init();
    ProcScheme::init();
    KDriverScheme::init();
    UserScheme::init();
}

pub fn mount_to(node: SchemeRef, to: SchemeRef, name: String) {
    to.write().mount(node.clone(), name.clone());
    node.write()
        .when_mounted(to.read().get_path() + &name + "/", Some(to.clone()));
}
